package com.sunfeng.netty.atguigu.protocoltcp2;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author 孙峰
 * @Description: TODO
 * @date 2020/12/11 10:48
 */
public class MyMessageEncoder extends MessageToByteEncoder<UserProtocol> {
    @Override
    protected void encode(ChannelHandlerContext ctx, UserProtocol msg, ByteBuf out) throws Exception {

        System.out.println("MyMessageEncoder 被调用");
        out.writeInt(msg.getLength());
        out.writeBytes(msg.getContent());
    }
}
